import config from "@/config/config";

//设置缓存
function setlocalStorage(name, val) {
  let data = val;
  if (val != undefined && val != null && typeof val == "object") {
    data = JSON.stringify(val);
  }
  localStorage.setItem(config.app_prefix + name, data);
}

//获取缓存
function getlocalStorage(name) {
  let data = localStorage.getItem(config.app_prefix + name);
  try {
    data = JSON.parse(data);
  } catch (err) {
    console.log(err);
  }
  return data;
}

const common = {
  setlocalStorage,
  getlocalStorage,
};

export default common;
